import React, {Component} from 'react';
import {
    Button,
    Tree 
} from 'antd';
const TreeNode = Tree.TreeNode;
class TreePanel extends Component {
    constructor(props) {
        super(props);
    }
    //获取

    //遍历节点
    getAllnode = (data) => {
        return data.map(val => {
            var className = ''
            className = val.type == 2 ? '功能操作权限____ ' : '页面浏览权限____ ';
            return (
                <TreeNode 
                    key={val.id}
                    title={className + val.name}
                >
                    {val.child.length > 0 ? this.getAllnode(val.child) : ''}
                </TreeNode>
            )
        });
    }

    render() {
        console.log('111',this.props.oldIds);
        var oldIds = [];
        if(this.props.oldIds) {
            oldIds = this.props.oldIds;
        }else {
            oldIds = []
        }
        
        return (
            <div>
                <div className="tree-p-box">
                    <div className="tree-p-box-left">
                        {this.props.treeData.length
                        ? <Tree
                            onSelect={this.props.onSelect}
                            checkable={this.props.checkable}
                            onCheck={this.props.onCheck}
                            defaultCheckedKeys={oldIds}
                            >
                            {this.props.treeData.map(data => {
                                return (<TreeNode 
                                            key={data.id}
                                            title={data.name}
                                        >
                                            {data.child.length > 0 ? this.getAllnode(data.child) : ''}
                                        </TreeNode>
                                        )
                            } )}</Tree>
                        : ''}
                    </div>
                </div>
                
            </div>
        )
    }
}

export default TreePanel